package j02zuoye;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/*
在子线程里，先打印"张三到达农贸市场"，线程休眠1秒，然后打印"张三正在挑选烧烤炉"，线程休眠3秒，接着打印"张三正在购买烧烤木炭"，线程休眠1秒，然后打印"张三正在返回教室"，线程休眠2秒，最后打印"张三到达教室"。
 */
public class J1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService es = Executors.newFixedThreadPool(3);
        Future<Boolean> zhangsan = es.submit(()->{
            System.out.println("张三到达农贸市场");
            Thread.sleep(1000);
            System.out.println("张三正在挑选烧烤炉");
            Thread.sleep(3000);
            System.out.println("张三正在购买烧烤木炭");
            Thread.sleep(1000);
            System.out.println("张三正在返回教室");
            Thread.sleep(2000);
            System.out.println("张三到达教室");
            return true;
        });
        /*
        先打印"李四到达农贸市场"，线程休眠1秒，然后打印"李四正在挑选烧烤食材"，线程休眠2秒，接着打印"李四正在返回教室"，线程休眠2秒，最后打印"李四到达教室"。
         */
        Future<Boolean> lisi = es.submit(()->{
            System.out.println("李四到达农贸市场");
            Thread.sleep(1000);
            System.out.println("李四正在挑选烧烤食材");
            Thread.sleep(2000);
            System.out.println("李四正在返回教室");
            Thread.sleep(2000);
            System.out.println("李四到达教室");
            return true;
        });
        if(zhangsan.get() && lisi.get()){
            System.out.println("大家都回来了，chufa!");
        }
        System.out.println(zhangsan.get());
        System.out.println(zhangsan.get());
        System.out.println(zhangsan.get());
        System.out.println(zhangsan.get());
        System.out.println(zhangsan.get());
    }
}
